package view.widgets;



import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

import business.coding.CandidateCenter;


/**
 * Clase para mostrar visualmente una tabla de direcciones y sus piod
 * @author 53385255R
 *
 */
public class CorpAndPIODTable extends NormalizationTable<CandidateCenter> {
	

	/**
	 * @param composite
	 * @param style
	 */
	public CorpAndPIODTable(Composite composite, int style)
	{
		super(composite, style);

		LABEL = "Corps";
		_label.setText(LABEL);
		
		_table.setFont( new Font(composite.getDisplay(),"Arial", 9, SWT.NONE ));
		_table.setHeaderVisible(true);
		_table.setLinesVisible(true);
		
		String[] titles = new String[] { "Codigo PIOD","","Corp","ISO", "PROVINCIA","INSTIT","ORGANISMO","DPTO"};
		String[]toolTips = new String[] { "","","","","","","","",""};

		for (int loopIndex = 0; loopIndex < titles.length; loopIndex++) {
			TableColumn column = null;
		//	if (loopIndex <= 4)
				column = new TableColumn(_table, SWT.NULL);
		//	else column = new TableColumn(_table, SWT.Hide);
			column.setText(titles[loopIndex]);
			column.setToolTipText(toolTips[loopIndex]);
		}

		addSort();
	}
	
	
	
	private void addSort()
	{
		_table.getColumn(0).addListener(SWT.Selection, new Listener() {
			public void handleEvent( Event e) {
				
				doSortStringColumn(0);
			}
					
		});
		
		_table.getColumn(2).addListener(SWT.Selection, new Listener() {
			public void handleEvent( Event e) {
				
				doSortStringColumn(2);
			}
					
		});
	}

	/**
	 * Implementacion del patron Template Method
	 */
	@Override
	public void setItemElement(CandidateCenter element, TableItem item) {
			
			item.setText(0, element.getCenter().getCODE());
			item.setText(1, element.getCorpWrapper().get_idcorp() + "");
			item.setText(2, element.getCorpWrapper().get_corp());
			item.setText(3, element.getCenter().getISO());
			item.setText(4, element.getCenter().getPROVINCIA());
			item.setText(5, element.getCenter().getINSTIT());
			item.setText(6, element.getCenter().getORGANISMO());
			item.setText(7, element.getCenter().getDPTO());
		
		
	}
	
	
	
	
}
